<template>
    <el-dialog
        title="打印设置"
        :visible.sync="show"
        width="600px"
    >
        <el-form ref="form" :model="form" label-width="80px">
            <el-form-item label="条码打印">
                <el-select v-model="form.qrcode" @change="getQrcodeIndex" placeholder="请选择活动区域" style="width: 100%;">
                    <el-option
                        v-for="item in print"
                        :label="item.label"
                        :value="item.value"
                        :key="item.value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="单据打印">
                <el-select v-model="form.zyd" @change="getZydIndex" placeholder="请选择活动区域" style="width: 100%;">
                    <el-option
                        v-for="item in print"
                        :label="item.label"
                        :value="item.value"
                        :key="item.value"
                    />
                </el-select>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="design">设 计</el-button>
            <el-button type="primary" @click="show = false">确 定</el-button>
        </span>
    </el-dialog>
</template>

<script>
import { getPrinterList } from '../../../utils/lodop/index.js'

export default {
    name: 'PrintConfig',
    props: {},
    data() {
        return{
            show: false,
            print: [],
            form: {}
        }
    },
    mounted() {
        this.print = getPrinterList()
        console.log('print', this.print)
        const qindex = window.localStorage.getItem('qrcodeIndex')
        const zindex = window.localStorage.getItem('zydIndex')
        qindex && (this.form.qrcode = qindex - 0)
        zindex && (this.form.zyd = zindex - 0)
    },
    methods: {
        design() {
            window.LODOP.PRINT_DESIGN()
        },
        open() {
            this.show = true
        },
        close() {
            this.show = false
        },
        getQrcodeIndex(e) {
            window.localStorage.setItem('qrcodeIndex', e)
            console.log('this.print[e].label', this.print[e].label)
            window.localStorage.setItem('qrcodeName', this.print[e].label)
        },
        getZydIndex(e) {
            window.localStorage.setItem('zydIndex', e)
            console.log('this.print[e].label', this.print[e].label)
            window.localStorage.setItem('zydName', this.print[e].label)
        }
    }
}
</script>

<style lang="scss" scoped>
</style>
